home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
120_01
/
meta4.met
< prev
next >
Wrap
Text File
|
1985-03-09
|
6KB
|
202 lines
.syn compile
.field value 0 type 3 ;
.constant name 1 field 3 constant 2 undefined 0
availfields 5
;
.name number '0' id '0' savid '2' temp 'z'
stack 'y' unstack '!'
;
rvalue =
idname &catname (':' idfield .cat ('m' id:value)
/ .emp )
/constsimp
.cat('n/' unstack ' ')
/ '+' expression .cat('!')
;
expression = term $( '+' term .out('!+')
/'-' term .out('!-')
)
;
term = factor
$( '*' factor .out('!*')
/ '/''256' .out('hz')
.out('!d')
.out('zy')
/ '%256'
.out('hy')
.out('n/''256*')
.out('!-')
)
;
factor = '(' expression ')'
/ constsimp .out('n/' unstack 'y' )
/ idname &catname (':' idfield .cat('m' id:value)
/ .emp ) .out('y')
/ '-' factor .out('!z')
.out('n/''0y')
.out('z-')
;
catname = id:value =: stack
.act('!l') ! acts as a one byte macro
;
toplace = idname id =: savid
(':' idfield .cat('i' id:value ) /.emp )
savid =: id &catname
;
declare = '.field' $( idnew id =: savid
constexp &checkfrange number =: savid:value
field =: savid:type
) ';'
/ '.name' $( idnew id=:savid
constexp unstack =: savid:value
name =: savid:type
) ';'
/ '.constant' $( idnew id =: savid
constexp constant =: savid:type
unstack =: savid:value
) ';'
;
constexp = constterm $( '+' constterm .act('!+')
/ '-' constterm .act('!-')
);
constterm = constfac $( '*' constfac .act('!*')
);
constsimp = .num number =: stack
/ idcons id:value =: stack
/ .str "'" .act('n/0sy') ! value is first character
/ '.x' .hexnum ]number
;
constfac = constsimp
/ '-' constfac .act('!z' 'n/0y' 'z-')
/ '(' constexp ')'
;
idtype = .act ('li' ! is it an id ??
'f/' *1 ! no, return
'me' ! define or find
'0m3y' 'z=' ! id.type == temp
'l' 'r' ! take and return
'.' *1 ! noe accept or rewind input
'l' 'z9' );
idname = .prep name =: temp idtype ;
idfield = .prep field =: temp idtype ;
idcons = .prep constant =: temp idtype ;
idnew = .prep undefined =: temp idtype ;
checkfrange = .if (number <= availfields)
.return
.else
.erms( number ' is too big for a field' )
.end
;
aout = '*1' .out('u')
/ '*2' .out('v')
/ '*' .out('c')
/ (.str "'" /.str'"') .out('p' *)
/ rvalue .out('c')
/ '.h' rvalue .out('h')
/ '.' .out('xn')
;
notsyn = ( '.out' '(' $ aout ')'
/ '.lab' .out('p... ') aout
)
.out('o')
/ '.act' '(' $( (.str "'" / .str '"') .act('c')
('*1' .act('u') / '*2' .act('v') / .emp)
.act('o')
/ .str '!'
) ')'
/ ']' rvalue .out('y')
/ rvalue '=:' toplace .out()
/ '.if' '(' cexp ')' .out('f/' *1) $ notsyn
('.else' .out('j/' *2) .lab*1 .out('s') $ notsyn '.end' .lab*2
/ '.end' .lab*1 .out('s') )
/ '.cat' '(' $aout ')'
/ '.condlab'
('*1' .out('uy')
.out('0=')
.out('t/' *1)
.out('p... ')
.out('u')
/'*2' .out('vy')
.out('0=')
.out('t/' *1)
.out('p... ')
.out('v')
)
.out('o')
.out('s') ! ! ! note side effect ! ! !
.lab *1
/ errormessage
/ '.error' .out('sf')
/ '.succeed' .out('s')
/ '.fail' .out('sf')
/ '&' idnew .out('g' *)
/ '.return' .out('r')
/ .str '!'
;
cright =
'==' .out('y') rvalue .out('=')
/ '!=' .out('y') rvalue .out('=') .out('sc')
/ '<=' .out('y') rvalue .out('<') .out('sc')
/ '>=' .out('y') rvalue .out('>') .out('sc')
/ '<' .out('y') rvalue .out('>')
/ '>' .out('y') rvalue .out('<')
;
cterm = cfac $( '.andif' .out('f/' *2) cfac) .condlab *2 ;
cfac = rvalue cright
/ '.not' cfac .out('sc')
/ '(' cexp ')'
/ '&' idnew .out('g' *)
;
cexp = cterm $( '.orif' .out('t/' *1) cterm) .condlab *1 ;
errormessage = '.erms' '(' .out('t/' *1) $aout ')' .out('xo') .lab *1 ;
syn = ( idnew .out('g' *)
/ .str "'" .out('lm' *) .out('l')
/ '.id' .out('li') .out('f/' *1) .out('l') .out('me') .lab *1
/ '.num' .out('ln') .out('l')
/ '.str' (.str "'" / .str '"') .out('lq' *) .out('l')
/ '.emp' .out('s')
/ '$' .lab *1 syn .out('t/' *1) .out('s')
/ '(' phrase ')'
/ '.hexnum' .out('lh') .out('l')
)
(errormessage / .emp)
;
seq = syn .out('f/' *1)
$( syn .out('x') / notsyn )
.lab *1
;
alts = seq $( '/' .out('t/' *1) seq ) .condlab *1 ;
phrase = '.prep' $notsyn alts / alts / notsyn $notsyn ;
statement = .id .lab * '=' phrase ';' .out('r') (.str '!' / .emp ) ;
compile = '.syn' .id .out('s') .out('xm') .out('g' *) .out('e')
.act('xm;') $ declare $ statement
;